/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.wechat.entity.WechatMediaId;
import com.boxin.ims.modules.wechat.dao.WechatMediaIdDao;

/**
 * 记录MediaIdService
 * @author XiaoQian
 * @version 2014-06-21
 */
@Component
@Transactional(readOnly = true)
public class WechatMediaIdService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(WechatMediaIdService.class);
	
	@Autowired
	private WechatMediaIdDao wechatMediaIdDao;
	
	public WechatMediaId get(Long id) {
		return wechatMediaIdDao.findOne(id);
	}
	
	public Page<WechatMediaId> find(Page<WechatMediaId> page, WechatMediaId wechatMediaId) {
		DetachedCriteria dc = wechatMediaIdDao.createDetachedCriteria();
		if (wechatMediaId.getUser()!=null && wechatMediaId.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", wechatMediaId.getUser().getId()));
		}
		dc.addOrder(Order.desc("id"));
		return wechatMediaIdDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(WechatMediaId wechatMediaId) {
		wechatMediaIdDao.save(wechatMediaId);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		wechatMediaIdDao.deleteById(id);
	}
	
}
